package object;

public class ToStringDemo {
    public static void main(String[] args) {
        /*
            toString()
            println(obj) 方法会自动调用obj的toString(),输出对象信息
            Object定义了toString()方法，所有子类都继承了了toString()
            Object提供的toString()默认返回值：类全名(全限定名)@散列值
            经常重写toString()方法，返回对象的描述
            开发工具提供了快速重写toString()的功能，重写时候利用此功能即可

         */
        Ship ship = new Ship();
        System.out.println(ship);
        Boat boat = new Boat();
        System.out.println(boat);
        Bomb bomb = new Bomb(1,2,4,5);
        System.out.println(bomb);
    }
}
class Ship{

}
class Boat{
    public String toString(){
        return "小船";
    }
    Boat(){

    }
}
class Bomb{
    private double x;
    private double y;
    private double w;
    private double h;

    @Override //通知编译器检查后续方法是否符合重写方法
    public String toString() {
        return "Bomb{" +
                "x=" + x +
                ", y=" + y +
                ", w=" + w +
                ", h=" + h +
                '}';
    }

    public Bomb(double x, double y, double w, double h) {
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
    }

}
